<template>
  <div class="enhanced-timeline">
    <h3 class="timeline-title">打卡记录</h3>

    <div class="timeline-container">
      <div
          v-for="(item, index) in timelineItems"
          :key="index"
          class="timeline-item"
      >
        <div class="timeline-dot"></div>
        <div class="timeline-content">
          <div class="timeline-header">
            <div class="timeline-time">{{ item.time }}</div>
            <div class="timeline-date">{{ item.date }}</div>
          </div>

          <div class="timeline-activity">
            <div class="activity-text">{{ item.activity }}</div>
            <div class="activity-desc">{{ item.description }}</div>
          </div>

          <div class="timeline-images" v-if="item.images && item.images.length > 0">
            <el-image
                v-for="(img, imgIndex) in item.images"
                :key="imgIndex"
                :src="img"
                fit="cover"
                class="activity-image"
                :preview-src-list="item.images"
            >
              <template #error>
                <div class="image-error">
                  <el-icon><Picture /></el-icon>
                </div>
              </template>
            </el-image>
          </div>
        </div>
      </div>

      <div v-if="timelineItems.length === 0" class="empty-tip">
        <el-icon><List /></el-icon>
        <p>暂无打卡记录</p>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { Picture, List } from '@element-plus/icons-vue';

const props = withDefaults(defineProps<{
  items?: Array<{
    date: string;
    time: string;
    activity: string;
    description: string;
    images?: string[];
  }>
}>(), {
  items: () => []
});

const timelineItems = computed(() => props.items || []);
</script>

<style scoped>
.enhanced-timeline {
  padding: 12px;
  height: 100%;
}

.timeline-title {
  margin: 0 0 12px 0;
  font-size: 15px;
  color: #333;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
}

.timeline-container {
  padding-left: 24px;
  position: relative;
}

.timeline-item {
  position: relative;
  padding-bottom: 16px;
}

.timeline-item:last-child {
  padding-bottom: 0;
}

.timeline-dot {
  position: absolute;
  left: -12px;
  top: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--el-color-primary);
  z-index: 1;
}

.timeline-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: -9px;
  top: 16px;
  width: 2px;
  height: calc(100% - 8px);
  background-color: var(--el-color-primary-light-5);
}

.timeline-content {
  background: #fff;
  border-radius: 6px;
  padding: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.timeline-date {
  font-size: 12px;
  color: #909399;
}

.timeline-time {
  font-size: 13px;
  color: var(--el-color-primary);
  font-weight: 500;
}

.timeline-activity {
  margin-bottom: 12px;
}

.activity-text {
  font-size: 14px;
  color: #333;
  margin-bottom: 4px;
  font-weight: 500;
}

.activity-desc {
  font-size: 13px;
  color: #606266;
  line-height: 1.5;
}

.timeline-images {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.activity-image {
  width: 80px;
  height: 80px;
  border-radius: 4px;
  object-fit: cover;
  cursor: pointer;
  border: 1px solid #eee;
}

.image-error {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f5f7fa;
  color: #c0c4cc;
}

.empty-tip {
  text-align: center;
  padding: 20px 0;
  color: #909399;
}

.empty-tip .el-icon {
  font-size: 24px;
  margin-bottom: 8px;
}

.empty-tip p {
  margin: 0;
  font-size: 14px;
}
</style>
